package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.User;
import top.tsyz.service.IUserService;

import java.util.List;

/**
 * UserController控制器
 */
@RestController
@RequestMapping("/api/users")
@Api(tags = "User管理接口")
public class UserController {

    @Autowired
    private IUserService iuserservice;

    @GetMapping("/list")
    @ApiOperation("获取所有User")
    public List<User> list() {
        return iuserservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取User")
    public User getById(@PathVariable Long id) {
        return iuserservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增User")
    public boolean save(@RequestBody User user) {
        return iuserservice.save(user);
    }

    @PutMapping
    @ApiOperation("更新User")
    public boolean update(@RequestBody User user) {
        return iuserservice.updateById(user);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除User")
    public boolean delete(@PathVariable Long id) {
        return iuserservice.removeById(id);
    }
}
